package org.example.order;

import org.example.dao.OrderDao;
import org.example.entity.Order;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version 1.0.0
 * Created by cyd on 2022-09-23 14:56:10
 */
@RestController
@RequestMapping(path = "/order")
public class OrderController {

    @Resource
    private OrderDao orderDao;

    @RequestMapping(path = "/createOrder/{userId}/{orderId}", method = {RequestMethod.GET})
    public String createOrder(@PathVariable("userId") Integer userId, @PathVariable("orderId") Integer orderId) {
        Order order = new Order();
        order.setOrderId(orderId);
        order.setUserId(userId);
        orderDao.createOrder(order);
        return "success";
    }

    @RequestMapping(path = "/{userId}", method = {RequestMethod.GET})
    public List<Order> getOrderListByUserId(@PathVariable("userId") Integer userId) {
        return orderDao.getOrderListByUserId(userId);
    }

    @RequestMapping(path = "/list", method = {RequestMethod.GET})
    public List<Order> getOrderListByUserId() {
        return orderDao.getOrderList();
    }

}
